package com.zhy.user.controller;


import com.zhy.bean.Result;
import com.zhy.user.entity.dto.UserDto;
import com.zhy.user.entity.req.UserListReq;
import com.zhy.user.mapper.UserMapper;
import com.zhy.user.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 随缘而愈
 * @version 1.0
 * @description TODO
 * @date 23/1/2024 下午5:25
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private UserMapper userMapper;

//    @PostMapping
//    public Result addUser(@RequestBody UserReq userReq){
//        UserDto userDto = new UserDto();
//        BeanUtils.copyProperties(userReq,userDto);
//        return Result.ok(userService.addUser(userDto));
//    }

    @DeleteMapping("/{id}")
    public Result deleteUser(@PathVariable Long id){
        System.out.println("id = " + id);
        return Result.ok(userService.delete(id));
    }

    @GetMapping
    private Result getPage(@RequestBody UserListReq userListReq){
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(userListReq,userDto);
        return Result.ok(userService.getUserPage(userDto));
    }


    @PostMapping
    public Result updateUser(@RequestBody UserDto userDto){
        return Result.ok(userService.update(userDto));
    }

}
